//
//  HOTContributionHIstoryDetailViewController.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-12.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTContributionHIstoryDetailViewController.h"
#import "UIImageView+AFNetworking.h"
#import "HOTImagePriviewer.h"

@interface HOTContributionHIstoryDetailViewController ()

@end

@implementation HOTContributionHIstoryDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setNaviTitle:@"掲示板投稿履歴"];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_ita"]];
    
    _contentTitleLabel.text = [HOTUtils getString:[self.detailInfo objectForKey:@"article_title"]];
    [_contentTitleLabel sizeToFit];
    _dateTimeLab.text = [HOTUtils getString:[self.detailInfo objectForKey:@"article_time"]];
    
    _cateLab.text = [HOTUtils getString:[self.detailInfo objectForKey:@"article_category"]];
    
    _contentLabel.text = [HOTUtils getString:[self.detailInfo objectForKey:@"article_content"]];;
    
    NSString *picUrlStr = [self.detailInfo objectForKey:@"pic_thumb_url"];
    
    if ([HOTUtils isNotNullOrEmpty:picUrlStr]) {
        
        UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentImageClicked)];
        [tgr setNumberOfTapsRequired:1];
        [tgr setNumberOfTouchesRequired:1];
        
        [_contentImageView addGestureRecognizer:tgr];
        _contentImageView.userInteractionEnabled = YES;
        
        NSURL *picUrl = [NSURL URLWithString:picUrlStr];
        
        [_contentImageView setImageWithURL:picUrl placeholderImage:kImageHolder];
    } else {
        
        for (NSLayoutConstraint *cons in _contentImageView.constraints) {
            
            if (cons.firstItem == _contentImageView && cons.firstAttribute == NSLayoutAttributeHeight) {
                
                cons.constant = 0;
                //continue;
            }
        }
        
        for (NSLayoutConstraint *cons in _contentLabel.superview.constraints) {
            
            if (cons.firstItem == _contentLabel
                && cons.firstAttribute == NSLayoutAttributeTop
                && cons.secondItem == _contentImageView
                && cons.secondAttribute == NSLayoutAttributeBottom) {
                
                cons.constant = 0;
            }
        }
    }
}

-(IBAction)contentImageClicked {
    
    NSString *urlStr = [_detailInfo objectForKey:@"pic_url"];
    
    if ([HOTUtils isNotNullOrEmpty:urlStr]) {
        
        [[HOTImagePriviewer priviewer] showInView:self.view withUrl:urlStr placeHolder:_contentImageView.image];
    } else {
        
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
